package com.timber.util;

import java.util.*;


public class ITPContractCorrectionMgr
{
  private static boolean DEBUG = false;

  /* Stored proc call to retrieve contract fields and their editable states  */

  public static SLDataMgr mgr = new SLDataMgr( "com.db.gef.util.ITPContractCorrection", "common..p_GetContractCorrectionMatrix" );

  public static void init() throws Exception
  {
    mgr.clear();
    mgr.runProc();
  }

  /* Return a specific contract field and editable states (ITPContractCorrection object);
  *  Pass in key (contract field name)
  */
  public static ITPContractCorrection getITPContractCorrection( Object key )
  {
    ITPContractCorrection ret = null;

    try
    {
      ret = ( ITPContractCorrection )mgr.getByKey( key );
    }
    catch( Exception ex )
    {
      ret = null;
    }
    return ret;
  }


  /* Return true/false to whether the column in question is allowed
  *  to be edited
  *  Pass in field name and correction type
  */

  public static boolean isFieldEditable(String fieldName, String correctionType )
  {
      String hashKey  = null;
      ITPContractCorrection ret = null;

      hashKey = fieldName;

      if (hashKey == null)    { return false; }

      ret = getITPContractCorrection(hashKey);
      if (ret == null)        { return false; }

      if (correctionType.equals(ITPContractCorrection.TRADE_CASH_AMEND) )
      {
          if ( (ret.getNewTradeCashAmend()).equals("Y") )         { return true; }
      }
      if (correctionType.equals(ITPContractCorrection.TRADE_CASH_CHANGE) )
      {
          if ( (ret.getNewTradeCashChange()).equals("Y") )         { return true; }
      }
      if (correctionType.equals(ITPContractCorrection.TRADE_NONCASH_AMEND) )
      {
          if ( (ret.getNewTradeNonCashAmend()).equals("Y") )         { return true; }
      }
      if (correctionType.equals(ITPContractCorrection.TRADE_NONCASH_CHANGE) )
      {
          if ( (ret.getNewTradeNonCashChange()).equals("Y") )         { return true; }
      }
      if (correctionType.equals(ITPContractCorrection.TRADE_CASHPOOL_AMEND) )
      {
          if ( (ret.getNewTradeCashPoolAmend()).equals("Y") )         { return true; }
      }
      if (correctionType.equals(ITPContractCorrection.TRADE_CASHPOOL_CHANGE) )
      {
          if ( (ret.getNewTradeCashPoolChange()).equals("Y") )         { return true; }
      }
      if (correctionType.equals(ITPContractCorrection.TRADE_COLL_NONCASH_AMEND) )
      {
          if ( (ret.getNewCollateralNonCashAmend()).equals("Y") )         { return true; }
      }
      if (correctionType.equals(ITPContractCorrection.TRADE_COLL_NONCASH_CHANGE) )
      {
          if ( (ret.getNewCollateralNonCashChange()).equals("Y") )         { return true; }
      }
      if (correctionType.equals(ITPContractCorrection.RETURN_CASH_AMEND) )
      {
          if ( (ret.getReturnTradeCashAmend()).equals("Y") )         { return true; }
      }
      if (correctionType.equals(ITPContractCorrection.RETURN_NONCASH_AMEND) )
      {
          if ( (ret.getReturnTradeNonCashAmend()).equals("Y") )         { return true; }
      }
      if (correctionType.equals(ITPContractCorrection.RETURN_CASHPOOL_AMEND) )
      {
          if ( (ret.getReturnTradeCashPoolAmend()).equals("Y") )         { return true; }
      }
      if (correctionType.equals(ITPContractCorrection.RETURN_COLL_NONCASH_AMEND) )
      {
          if ( (ret.getReturnCollateralNonCashAmend()).equals("Y") )         { return true; }
      }

      return false;
  }


  public static Vector getItems() throws Exception
  {
    return mgr.getKeyList();
  }

  public static Vector getDataVector() throws Exception
  {
    return mgr.getDataVector();
  }



}